Page({
	data: {
		movies: [{}],
		showList: [],
		imageUrl: getApp().globalData.imageUrl,
		shopName: '请选择门店'
	},
	onShow: function(options) {
		this.getShopName();
		// 获取底部图片
		this.getBanner(2);
		//获取我的取餐码和我的拼团信息
		this.getCodeAndGroup();
		wx.startWifi({
			success: function() {
				wx.getConnectedWifi({
					success: function(res) {
						console.log("getConnectedWifiSuccess")
						console.log(res)
					},
					fail: function(res) {
						console.log("getConnectedWifiFail")
						console.log(res)

					}
				})


			}


		})



	},
	formSubmit: function(e) {
		console.log(e.detail.formId);
	},
	fitBanner: function() {

		var winWidth;
		var winHeight;
		wx.getSystemInfo({
			success: function(res) {
				winWidth = res.windowWidth;
				winHeight = res.windowHeight;
			}
		})

		var viewHeight = winHeight * 750 / winWidth; //banner高度
		console.log('****')

		console.log(viewHeight)
		console.log(viewHeight - 180 - 180 - 300)
		var imageHeight = (viewHeight - 180 - 180 - 300);
		if (imageHeight > 500) {
			// 获取顶部图片
			console.log("请求大图")
			this.getBanner(0);
			imageHeight = 630;
		} else {
			this.getBanner(1);
			imageHeight = 420;
		}
		this.setData({
			imageHeight: imageHeight
		})
	},
	getCodeAndGroup: function() {
		var _self = this;
		wx.request({
			url: getApp().globalData.baseUrl + '/applet/group/getJoinGroupsAndOrders.do',
			header: getApp().globalData.header,
			data: {
				shopCode: getApp().globalData.common.reserveShopCode || '',
			},
			success: function(res) {
				console.log(res)
				if (res.data.code == 200) {
					if (res.data.obj.orders > 1 || res.data.obj.groups > 1) {
						_self.getBanner(1);
						_self.setData({
							imageHeight: 420
						})
					} else {
						_self.fitBanner();
					}
					_self.setData({
						codeList: res.data.obj.orders,
						groupList: res.data.obj.groups
					})
				} else {
					_self.setData({
						codeList: []
					})
				}
			}
		})

	},

	getBanner: function(type) {
		if (type == 0) {
			console.log('请求大图成功')
		}
		var _self = this;
		wx.request({
			url: getApp().globalData.baseUrl + '/applet/banner/getBanner.do?bannerType=' + type,
			data: {
				shopCode: getApp().globalData.common.reserveShopCode || '',
			},
			header: getApp().globalData.header,
			success: function(res) {
				console.log(res)
				if (res.data.code == 200) {

					if (type == 1) {
						_self.setData({
							movies: res.data.obj
						})
					} else if (type == 2) {

						_self.setData({
							btUrl: res.data.obj
						})


					} else if (type == 0) {
						_self.setData({
							movies: res.data.obj
						})
					}
				} else {

				}
			}
		})

	},
	turn: function(e) {
		console.log(e.currentTarget.dataset.path)
		var path = e.currentTarget.dataset.path;
		wx.switchTab({
			url: path
		})
	},
	turnOrderDetail: function(e) {
		var url = '/pages/reserveOrder/reserveOrder?code=' + e.currentTarget.dataset.code;
		wx.navigateTo({
			url: url
		})
	},
	turnGroupDetail: function(e) {
		var type = e.currentTarget.dataset.type; //成功失败信息
		var code = e.currentTarget.dataset.code; //订单号
		var gid = e.currentTarget.dataset.gid; //团id
		var urlString;
		if (type == 0) {
			urlString = '/pages/groupDetail/groupDetail?orderCode=' + code;
		} else {
			urlString = '/pages/myGroupDetail/myGroupDetail?groupCode=' + gid;
		}

		wx.navigateTo({
			url: urlString
		})
	},
	turnTar: function(e) {
		var path = e.currentTarget.dataset.code;

		if (path.indexOf('http') > -1) {
			wx.navigateTo({
				url: '/pages/test/test?path=' + path
			})
			return
		}

		if (path) {
			wx.switchTab({
				url: path
			})
		} else {
			console.log('没有')
		}
	},
	turnSecondPage: function(e) {
		var path = e.currentTarget.dataset.code;
		if (!path) {
			return
		}
		if (path.indexOf('http') > -1) {
			wx.navigateTo({
				url: '/pages/test/test?path=' + path
			})
			return
		}

		if (path) {
			wx.navigateTo({
				url: path
			})
		} else {
			console.log('没有')
		}

	},
	chooseShop: function() {
		wx.navigateTo({
			url: '/pages/reserveShops/reserveShops'
		})
	},
	getShopName: function() {
		if (!getApp().globalData.common.reserveShopCode) {
			return
		}
		var _self = this;
		wx.request({
			url: getApp().globalData.baseUrl + '/applet/shop/getShop.do',
			data: {
				shopCode: getApp().globalData.common.reserveShopCode || '',
			},
			header: getApp().globalData.header,
			success: function(res) {
				if (res.data.code == 200) {
					getApp().globalData.common.longitude = res.data.obj.longitude;
					getApp().globalData.common.latitude = res.data.obj.latitudes;

					_self.setData({
						shopName: "当前门店：" + res.data.obj.shopName
					});
				} else if (res.data.code == 507) {
					_self.setData({
						shopName: '门店歇业'
					});
				} else {
					_self.setData({
						shopName: '请选择门店'
					});
				}
			}
		})
	},
	goGroup: function() {
		wx.switchTab({
			url: '/pages/group/group'
		})
	}
})